<template>
  <a-spin :spinning="loading">
    <div>
      <a-form-model
        class="fromModels"
        ref="largeDividendModel"
        layout="vertical"
        :labelCol="{ span: 10 }"
        :wrapperCol="{ span: 14 }"
      >
        <div class="centes">
          <div class="centes_confis">
            <a-form-model-item label="大盘分红开关">
              <a-radio-group v-model="status">
                <a-radio :value="1"> 开 </a-radio>
                <a-radio :value="0"> 关 </a-radio>
              </a-radio-group>
            </a-form-model-item>
            <a-form-model-item label="下发规则">
              <a-radio-group v-model="config.rule">
                <a-radio :value="1"> 首次交易 </a-radio>
                <a-radio :value="0"> 注册时间 </a-radio>
              </a-radio-group>
            </a-form-model-item>
            <a-form-model-item label="下发日期">
              <a-input v-model="config.day">
                <div slot="addonAfter">号</div>
              </a-input>
            </a-form-model-item>
            <a-form-model-item label="显示类型">
              <a-radio-group v-model="config.show_type">
                <a-radio :value="1"> 实时显示 </a-radio>
                <a-radio :value="2"> 定时显示 </a-radio>
              </a-radio-group>
            </a-form-model-item>
            <a-form-model-item label="时间点">
              <a-input v-model="config.show_time">
                <div slot="addonAfter">点</div>
              </a-input>
            </a-form-model-item>
            <a-form-model-item label="税费费率">
              <a-input v-model="config.tax_rate">
                <div slot="addonAfter">万</div>
              </a-input>
            </a-form-model-item>
          </div>
        </div>

        <div class="confish">
          <div class="confish_items">
            <a-form-model-item :wrapperCol="{ span: 14, offset: 10 }">
              <div>代还</div>
            </a-form-model-item>
            <a-form-model-item label="代还开关开关">
              <a-radio-group v-model="config.repayment_status">
                <a-radio :value="1"> 开 </a-radio>
                <a-radio :value="0"> 关 </a-radio>
              </a-radio-group>
            </a-form-model-item>
            <a-form-model-item
              v-for="(item, index) in config.repayment"
              :key="'repayment' + index"
              :label="'规则' + (Number(index) + 1) + ' 级别-费率'"
            >
              <div class="disse">
                <a-select v-model="item.id">
                  <a-select-option v-for="(item, index) in levelArrs" :key="index" :value="item.level">{{
                    item.name
                  }}</a-select-option>
                </a-select>
                <span class="margin_lr5">-</span>
                <a-input v-model="item.rate">
                  <div slot="addonAfter">万</div>
                </a-input>
              </div>
            </a-form-model-item>
          </div>

          <div class="confish_items">
            <a-form-model-item :wrapperCol="{ span: 14, offset: 10 }">
              <div>级别订单</div>
            </a-form-model-item>
            <a-form-model-item label="级别订单开关">
              <a-radio-group v-model="config.repayment_money">
                <a-radio :value="1"> 开 </a-radio>
                <a-radio :value="0"> 关 </a-radio>
              </a-radio-group>
            </a-form-model-item>
            <a-form-model-item
              v-for="(item, index) in config.levelorder"
              :key="'levelorder' + index"
              :label="'规则' + (Number(index) + 1) + ' 级别-费率'"
            >
              <div class="disse">
                <a-select v-model="item.id">
                  <a-select-option v-for="(item, index) in levelArrs" :key="index" :value="item.level">{{
                    item.name
                  }}</a-select-option>
                </a-select>
                <span class="margin_lr5">-</span>
                <a-input v-model="item.rate">
                  <div slot="addonAfter">万</div>
                </a-input>
              </div>
            </a-form-model-item>
          </div>
        </div>

        <a-form-model-item :wrapper-col="{ span: 12, offset: 5 }">
          <a-button type="primary" @click="whites">提交</a-button>
          <a-button type="primary" @click="reset">重置</a-button>
        </a-form-model-item>
      </a-form-model>
    </div>
  </a-spin>
</template>

<script>
import { getRebateApi, setRebateApi, getLevelApi } from '@/api/return.js'
export default {
  name: 'largeDividend',

  data() {
    return {
      loading: false,
      config: {
        collection: [],
        collection_money: '',
        count: 1,
        end_day: '',
        repayment: [],
        repayment_money: '',
        rule: 1,
        tax_rate: '0',
        time: 1
      },
      status: 1,
      levelArrs: []
    }
  },
  created() {
    this.getPrivacyAgreementInfo()
    this.getLevelApi()
  },
  methods: {
    reset() {
      this.getPrivacyAgreementInfo()
      this.getLevelApi()
    },
    getLevelApi() {
      getLevelApi({
        brand_id: process.env.VUE_APP_BRAND_ID
      }).then(res => {
        this.levelArrs = res.data
      })
    },

    getPrivacyAgreementInfo() {
      this.loading = true
      getRebateApi({
        type: 'composite_rebate',
        brand_id: process.env.VUE_APP_BRAND_ID
      })
        .then(res => {
          this.config = res.data.config
          this.status = res.data.status
        })
        .finally(() => {
          this.loading = false
        })
    },
    whites() {
      this.setDatas()
    },
    setDatas() {
      setRebateApi({
        type: 'composite_rebate',
        brand_id: process.env.VUE_APP_BRAND_ID,
        status: this.status,
        data: this.config
      }).then(res => {
        this.getPrivacyAgreementInfo()
        this.getLevelApi()
        this.$message.success('操作成功')
      })
    }
  }
}
</script>

<style lang="less" scoped>
.centes {
  display: flex;
  justify-content: center;
  margin-bottom: 30px;
}
.centes_confis {
  width: 50%;
}
.confish {
  display: flex;
  align-items: self-start;
  justify-content: space-between;
}
.confish_items {
  width: 48%;
}
</style>
